#!perl -T

use strict;
use warnings;
use Test::More;
use Date::Simple qw/date today ymd/;

BEGIN {
	use_ok( 'NaturalDateGuesser' );
}

my $parser = NaturalDateGuesser->new();

my $today = today();
my $day_of_week = $today->day_of_week;


my $list = [
[ "TODAY", $today ],
[ "ToDaY", $today ],
[ "today", $today ],
[ "tOday", $today ],
[ "Yesterday", $today - 1 ],
[ "YeSTeRDay", $today - 1 ],
[ "yesterday", $today - 1 ],
[ "YESTERDAY", $today - 1 ],
[ "20TH JAN 2003", ymd(2003,1,20) ],
[ "20rD MARch 2005", ymd(2005,3,20) ],
[ "neXt mOnday", $today + next_calc($day_of_week, 8) ], 
];

plan tests => scalar @$list;

foreach my $item (@$list)
{
	my ($string, $expected) = @$item;
	is($parser->parseDate($string), $expected, 
		"Parse $string");
}

sub next_calc
{
	my ($day_of_week, $base) = @_;
	my $result = ($base - $day_of_week) % 7;
	if(!$result)
	{
		$result = 7;
	}
	return $result;
}
